/****************************************************
          File Name:7-9.cpp
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Sat 20 Dec 2014 02:37:48 PM CST
*****************************************************/

#include<iostream>
#include<cstring>
using namespace std;

const int SLEN = 30;

struct student {
    char fullname[SLEN];
    char hobby[SLEN];
    int cooplevel;
};

int getinfo(student pa[], int n)
{
    int i;

    for(i = 0; i < n; i++)
    {
        cout << "Enter student's name: ";
        cin.getline(pa[i].fullname, SLEN);
        if(strcmp(pa[i].fullname, "") == 0)
            break;
        cout << "Enter student's hobby: ";
        cin.getline(pa[i].hobby, SLEN);
        cout << "Enter student's cooplevel: ";
        (cin >> pa[i].cooplevel).get();
    }

    return i;
}

void display1(student st)
{
    cout << "Display1" << endl;
    cout << "Name: " << st.fullname << endl;
    cout << "Hobby: " << st.hobby << endl;
    cout << "Cooplevel: " << st.cooplevel << endl;
}

void display2(const student *ps)
{
    cout << "Display2" << endl;
    cout << "Name: " << ps->fullname << endl;
    cout << "Hobby: " << ps->hobby << endl;
    cout << "Cooplevel: " << ps->cooplevel << endl;
}

void display3(const student pa[], int n)
{
    cout << "Display3" << endl;
    for(int i=0; i<n; i++)
    {
        cout << "Name: " << pa[i].fullname << endl;
        cout << "Hobby: " << pa[i].hobby << endl;
        cout << "Cooplevel: " << pa[i].cooplevel << endl;
    }
}

int main()
{
    cout << "Enter class size: ";
    int class_size;
    cin >> class_size;

    while(cin.get() != '\n')
        continue;

    student *ptr_stu = new student[class_size];
    int entered = getinfo(ptr_stu, class_size);

    for(int i=0; i<entered; i++)
    {
        display1(ptr_stu[i]);
        display2(&ptr_stu[i]);
    }

    display3(ptr_stu, entered);
    
    delete [] ptr_stu;
    cout << "Done\n";

    return 0;
}
